<?php
/**
 * Created by PhpStorm.
 * User: 陈艺赫
 * Date: 2017/12/12
 * Time: 2:50
 */

namespace Home\Controller;


class HmlistController extends BaseController
{
    public function index()
    {
        if (empty(session('guest'))) {
            $this->success('请先登录!');
            exit;
        }
        if (IS_GET) {
            $qm = I('get.qm');
            $hy = I('get.hy');
            $gs = I('get.gs');
            $db_history = M('history');
            $data_history = $db_history->where('guest_id = ' . session('guest')['id'])->select();

            $this->assign('qm', $qm);
            $this->assign('hy', $hy);
            $this->assign('gs', $gs);
            $this->assign('history', $data_history);
        }
        $this->display();
    }

    public function dataGet()
    {
        if (IS_POST) {
            $qm = I('post.qm');
            $hy = I('post.hy');
            $gs = I('post.gs');
            $db_company = M('company');
            $data_company = $db_company->where("txt like '%" . $qm . "%'")->select();
            $data['data'] = $data_company;
            $data['count'] = count($data_company);

            $db_history = M('history');
            $data['guest_id'] = session('guest')['id'];
            $data['txt'] = '淄博' . $qm . $hy . $gs;
            $map['txt'] = $data['txt'];
            $map['guest_id'] = session('guest')['id'];
            if ($data['count'] == 0) {
                $data['status'] = '高';
            } else {
                $data['status'] = '低';
            }
            $check = $db_history->where($map)->select();
            if (count($check) == 0) {
                $db_history->add($data);
            }

            $this->ajaxReturn($data);

        }
        $this->error('error');
    }
}